<template>
	<view class="zai-box">
		<image src="../../static/register.png" mode='aspectFit' class="zai-logo"></image>
		<view class="zai-title">LOGO区域</view>
		<view class="zai-form">
			<input class="zai-input" v-model="info.userName" placeholder="请输入用户名" />
			<input class="zai-input" v-model="info.password" password placeholder="请输入密码" />
			<input class="zai-input" v-model="info.password1" password placeholder="请确认密码" />
			<input class="zai-input" v-model="info.phonenumber" placeholder="请输入手机号" />
			<radio-group name="radio" class="zai-input" @change="getSex">
				<label class="sex">
					<radio value="0" checked="" /><text>男</text>
				</label>
				<label class="sex">
					<radio value="1" /><text>女</text>
				</label>
			</radio-group>
			<button class="zai-btn" @click="register">立即注册</button>
			<navigator url="../login/login" open-type='navigateBack' hover-class="none" class="zai-label">
				已有账号，点此去登录.</navigator>
		</view>
	</view>
</template>

<script>
	import {
		userRegister
	} from '../../api/user';
	export default {
		data() {
			return {
				info: {
					userName: "",
					password: "",
					password1: "",
					phonenumber: "",
					sex: 0
				}
			}
		},
		methods: {
			getSex(e) {
				// console.log('e:', e);
				this.info.sex = e.detail.value;
			},
			async register() {
				console.log(this.info);
				let res = await userRegister(this.info);
				console.log(res);
				let code = res.data.code;
				if (code === 500) {
					uni.showModal({
						title: "注册失败",
						content: res.data.mas,
						success: function(res) {
							if (res.confirm) {
								console.log("确定");
							} else if (res.cancel) {
								console.log("取消");
							}
						}
					});
				} else if (code == 200) {
					uni.navigateTo({
						url: "../login/login"
					})
				}
			}
		}
	}
</script>

<style>
	.zai-box {
		padding: 0 100upx;
		position: relative;
	}

	.zai-logo {
		width: 100%;
		width: 100%;
		height: 310upx;
	}

	.zai-title {
		position: absolute;
		top: 0;
		line-height: 360upx;
		font-size: 68upx;
		color: #fff;
		text-align: center;
		width: 100%;
		margin-left: -100upx;
	}

	.zai-form {
		margin-top: 300upx;
	}

	.zai-input {
		background: #e2f5fc;
		margin-top: 30upx;
		border-radius: 100upx;
		padding: 20upx 40upx;
		font-size: 36upx;
	}

	.input-placeholder,
	.zai-input {
		color: #94afce;
	}

	.zai-label {
		padding: 60upx 0;
		text-align: center;
		font-size: 30upx;
		color: #a7b6d0;
	}

	.zai-btn {
		background: #ff65a3;
		color: #fff;
		border: 0;
		border-radius: 100upx;
		font-size: 36upx;
		margin-top: 60upx;
	}

	.zai-btn:after {
		border: 0;
	}

	/*按钮点击效果*/
	.zai-btn.button-hover {
		transform: translate(1upx, 1upx);
	}

	.sex {
		margin-right: 100rpx;
	}
</style>